<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">		
 <title><? echo $title ?></title>
<? require("lib.php"); ?>
</head>
<body>
<div class="content-box"><!-- Start Content Box -->
  <div class="content-box-header">
      <h3><? echo $title ?></h3>
      <div class="clear"></div>
  </div> <!-- End .content-box-header -->
  <div class="content-box-content">
<?
  switch ($do) {
    case "add":
    	add();
    	break;
	case "update":
		update($info);
		break;
  case "flip":
    flip($id);
    break;
	case "delete":
		delete($id);
		break;
    default:
		show_info($info);
  }
 ?>
  <? function show_box($row, $iseditmode, $isadd=0){ 
			global $id, $h, $url, $title, $cate, $cateid, $cate_name, $baseurl, $option, $arrlang, $code_array, $lang;
      $arr_mode=$code_array['document_view_mode'];
      $has_pic=1; if(isset($row['has_pic']))$has_pic=$row['has_pic'];
      $has_field1=1; if(isset($row['has_field1']))$has_field1=$row['has_field1'];
      $has_field2=0; if(isset($row['has_field2']))$has_field2=$row['has_field2'];
      $has_field3=0; if(isset($row['has_field3']))$has_field3=$row['has_field3'];
		?>
        	<table width="99%" cellspacing="0" cellpadding="3" class="mbox">
              <tr class="th"><td class="thtitle" width="120" align="right"><? echo $title ?></td>
                <td>
                <? echo $h->hidden('id', $row["id"]); ?>
                <? echo $h->hidden('cid', $cateid); ?></td></tr>
                <tr><td class="l"><?=ROOT_PARENT_CATEGORY?></td><td><input value="<? echo $cate_name ?>" class="g" disabled /></td></tr>
              <?
                $str='';
                foreach($arrlang as $val){ // 加载所有启用的分语言的字段, add all fields that marked by languages
                  $str.='<tr><td class="l">'.ROOT_NAME.'('.$val['name'].')</td><td>'.$h->text('name_'.$val['code'], iso($row["name_".$val['code']]), 'g').'</td></tr>';
                  //$str.='<tr><td class="l">'.ROOT_INTRO.'('.$val['name'].')</td><td>'.$h->textarea('description_'.$val['code'], iso($row["description_".$val['code']]), 32, 4, ' g', '').'</td></tr>';
                }
                echo $str;
              ?>
              <? $hide=''; if(! $option['document_category']['pic']) $hide=' class="hide" '; ?>
              <tr <? echo $hide ?>><td class="l"><?=ROOT_PICTURE?></td><td>
              <? if(!$isadd)echo '<img src="'.$baseurl.'upload/'.decode($row["pic"]).'" height="72" /><br />'; ?>
              <? echo $h->cfile('cpic', 'g') ?> <span class="red"> <?=ROOT_CONTACT_ADMIN_FOR_PIC_SIZE_CHANGE?></span>
              </td></tr>
              <? $hide=''; if($cateid>0)  $hide=' class="hide" '; // 图片及图片尺寸在顶级分类配置, 子分类不需要配置 ?>
              <tr <? echo $hide ?>><td class="l"><?=ROOT_VIEW_MODE?></td><td><? echo $h->select('view_mode', $row["view_mode"], $arr_mode, 'id', 'name_'.$lang, 'g') ?></td></tr>
              <tr <? echo $hide ?>><td class="l"><?=ROOT_IAMGE?></td><td>&nbsp; <label><? echo $h->checkbox('has_pic',$has_pic); ?>  <?=ROOT_NEED_PIC?></label></td></tr>
              <tr <? echo $hide ?>><td class="l"><?=ROOT_PICTURE_SIZE_RATIO?></td><td><?=ROOT_WIDTH?> <? echo $h->text('pic_width', iso($row["pic_width"]), 'gmin') ?> px &nbsp; &nbsp; <?=ROOT_HEIGHT?> &nbsp; <? echo $h->text('pic_height', iso($row["pic_height"]), 'gmin') ?> px</span></td></tr>
              <? // 字段1
                $str='';
                foreach($arrlang as $val){ // 加载所有启用的分语言的字段, add all fields that marked by languages
                  $str.=' &nbsp; '.ROOT_NAME.'('.$val['name'].') '.$h->text('field1_'.$val['code'], iso($row["field1_".$val['code']]), 'gs').'';
                }
              ?>
              <tr <? echo $hide ?>><td class="l"><?=ROOT_FIELD?>1</td><td>&nbsp; <label><? echo $h->checkbox('has_field1',$has_field1); ?> <?=ROOT_YES?></label><? echo $str ?></td></tr>
              <? // 字段2
                $str='';
                foreach($arrlang as $val){ // 加载所有启用的分语言的字段, add all fields that marked by languages
                  $str.=' &nbsp; '.ROOT_NAME.'('.$val['name'].') '.$h->text('field2_'.$val['code'], iso($row["field2_".$val['code']]), 'gs').'';
                }
              ?>
              <tr <? echo $hide ?>><td class="l"><?=ROOT_FIELD?>2</td><td>&nbsp; <label><? echo $h->checkbox('has_field2',$has_field2); ?> <?=ROOT_YES?></label><? echo $str ?></td></tr>
              <? // 字段3
                $str='';
                foreach($arrlang as $val){ // 加载所有启用的分语言的字段, add all fields that marked by languages
                  $str.=' &nbsp; '.ROOT_NAME.'('.$val['name'].') '.$h->text('field3_'.$val['code'], iso($row["field3_".$val['code']]), 'gs').'';
                }
              ?>
              <tr <? echo $hide ?>><td class="l"><?=ROOT_FIELD?>3</td><td>&nbsp; <label><? echo $h->checkbox('has_field3',$has_field3); ?> <?=ROOT_YES?></label><? echo $str ?></td></tr>

              <tr><td class="l"><?=ROOT_ORDER?></td><td><? echo $h->text('seq_no', iso($row["seq_no"]), 'gs') ?> <span class="red"> <?=ROOT_HIGHER_NUMBER_IN_FRONT?></span></td></tr>
              <tr><td class="l">&nbsp;</td><td><br><? echo $h->submit('save', '&nbsp; '.ROOT_SAVE.' &nbsp;', $iseditmode==1?'':'hide') ?>&nbsp;&nbsp;<a onClick="history.go(-1)">[ <?=ROOT_CANCEL?> ]</a><br><br></td></tr>
            </table>
            <? } ?>
			<? function show_boxes($result){
				global $url, $page, $pages, $cateid, $cate, $s, $lang;
        		$str='<table width="99%" cellspacing="0" class="mlist"><tr class="th"><td><strong>&nbsp;</strong></td><td><strong>'.ROOT_NAME.'/'.ROOT_ADD_SUB_CATEGORY.'</strong></td><td><strong>'.ROOT_ORDER.'</strong></td><td><a href="'.$url.'.php?do=add">[ '.ROOT_ADD_TOP_CATEGORY.' ]</a></td></tr>';
				$tree=array(); // tree = category tree 分类树
        $tree=unlimitedlevel($result);
        //print_r($tree);
        $count=1;
        foreach( $tree as $row)
				{
          $id=decode($row['id']);
          $enable=$row['is_enabled']?ROOT_DISABLE:ROOT_ENABLE;
          $css_enable=($row['is_enabled'])?'':" class='disabled'";

          if($row['level']>3) continue; // level <= 3, 最大级别为3级
          $will_add_sub="<a href=\"$url.php?do=add&cid=".$id."\">+".ROOT_ADD_SUB_CATEGORY."</a>";
          if($row['level']==2) $will_add_sub='';
        $str.="<tr ".$css_enable."><td>&nbsp;</td><td>".$row['html_prefix'].decode($row['name_'.$lang])." &nbsp; ".$will_add_sub."</td><td>".$row['seq_no']."</td><td><a href=\"$url.php?do=update&cid=".$row['parent_category_id']."&id=".$id."\">".ROOT_UPDATE."</a> | <a href=\"$url.php?do=flip&id=".$id."\">".$enable."</a> | <a href=\"$url.php?do=delete&id=".$id."\" onClick=\"javascript: return delc();\">".ROOT_DELETE."</a></td></tr>";
					$count++;
				}
				$str.= "</table>";
				echo $str;
				if($count==1) echo "<br>".ROOT_NO_DATA."!";
				// echo echo_page($page, $pages, $url.'-'.$cateid.'-p');
             } ?>
         <br class="clear" />
				</div> <!-- End .content-box-content -->
        <br class="clear" />
			</div><!-- End .content-box -->
</body>
</html>